require( '$d/css/common.less' );
require( './style.less' );
define( [
  'jquery',
  'require',
  'message',
  'api',
  'h2Api',
  'bigwe_utils',
  'constants',
  'combiner',
  'behavior',
  'selector',
  'lazyload',
], function( $, require ) {
  var bu = require( 'bigwe_utils' );
  var c = require( 'constants' );
  var BIGWE_API = require( 'api' );
  var h2Api = require( 'h2Api' );
  var apis = require( 'api' );

  var ShowTitleMessage = require( 'message' );
  var behavior = require( 'behavior' );
  var showTime = ShowTitleMessage.showTime;
  $( ".con_left img" ).lazyload( {
    effect: "fadeIn",
    failure_limit: 10
  } );

  $( '.selectpicker' ).selectpicker( {
    size: 5,
    dropupAuto: false
  } );
  $( window ).scrollTop( 0 );

  // 移动端适配
  var isMobile = {
    Android: function() {
      return navigator.userAgent.match( /Android/i ) ? true : false;
    },
    BlackBerry: function() {
      return navigator.userAgent.match( /BlackBerry/i ) ? true : false;
    },
    iOS: function() {
      return navigator.userAgent.match( /iPhone|iPad|iPod/i ) ? true : false;
    },
    Windows: function() {
      return navigator.userAgent.match( /IEMobile/i ) ? true : false;
    },
    any: function() {
      return ( isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows() );
    }
  };
  if ( !isMobile.any() ) {
    $( '.con_head' ).keepOn( {
      style: {
        'left': '50%',
        'margin-left': '-515px',
        'margin-bottom': '0',
      }
    } );
    if ( ( $( window ).height() - 371 ) - ( $( window ).height() - 411 ) % 88 < 100 ) {
      $( '.guess_like' ).addClass( 'hide' );
    } else {
      $( '.guess_like' ).removeClass( 'hide' );
      $( '.guess_like' ).css( {
        height: ( ( $( window ).height() - 371 ) - ( $( window ).height() - 411 ) % 88 ) + 'px'
      } )
    }
    $( window ).resize( function() {
      var l = $( window ).height() - 371;
      var j = ( l - 40 ) % 88;
      var h = l - j;
      if ( h < 100 ) {
        $( '.guess_like' ).addClass( 'hide' );
      } else {
        $( '.guess_like' ).removeClass( 'hide' );
        $( '.guess_like' ).css( {
          height: h + 'px'
        } )

      }
    } )
  } else {
    $( '#main_content > table' ).attr( 'width', '100%' );
    $( '.account_info > a' ).attr( 'href', 'javascript:void(0)' );
  }

  ( function() {
    var tencentVoiceUrl = 'http://res.wx.qq.com/voice/getvoice?mediaid=';
    var idStr = 'bwVoice_',
      idLastStr = '_0';

    function getVoiceHtml( voice ) {

      var playLenght = ( voice.attr( 'play_length' ) || 0 ) / 1e3,
        playMin = ( playLenght / 60 ).toFixed( 0 ),
        playSecends = playLenght % 60;
      if ( ( '' + playSecends ).length == 1 ) {
        playSecends = '0' + playSecends;
      }
      var voiceID = voice.attr( 'voice_encode_fileid' );

      var html = '';
      html += '<span voice_encode_fileid="' + voiceID + '" id="voice_main_' + voiceID + idLastStr + '" class="db audio_area ">';
      html += '<span class="tc tips_global unsupport_tips" style="display:none;">当前浏览器不支持播放音乐或语音，请在微信或其他浏览器中播放</span>';
      html += '<span class="audio_wrp db">';
      html += '<span id="voice_play_MjM5ODc2NTY5NV8yNjQ5NDM2MDcy_0" class="audio_play_area">';
      html += '<i class="icon_audio_default"></i>';
      html += '<i class="icon_audio_playing"></i>';
      html += '<img src="http://res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/audio/icon_audio_unread26f1f1.png" alt="" class="pic_audio_default">';
      html += '</span>';
      html += '<span class="audio_length tips_global">' + playMin + ':' + playSecends + '</span>';
      html += '<span class="db audio_info_area">';
      html += '<strong class="db audio_title">' + decodeURI( voice.attr( 'name' ) ) + '</strong>';
      //html += '<span class="audio_source tips_global">来自</span>';
      html += '</span>';
      html += '<span id="voice_progress_' + voiceID + '" class="progress_bar" style="width:0px;"></span>';
      html += '</span>';
      html += '</span>';

      return html;
    }

    function loopVoice( index, item ) {

      var currentVoice = $( item );
      currentVoice.after( getVoiceHtml( currentVoice ) );
    }

    function playaudio() {

      var voiceID = $( this ).attr( 'voice_encode_fileid' );
      var voicePlayObj = $( document.getElementById( idStr + voiceID + idLastStr ) );
      if ( voicePlayObj.length ) {
        if ( voicePlayObj[ 0 ].paused ) {
          voicePlayObj[ 0 ].play();
          $( this ).addClass( 'playing' )
          voicePlayObj.attr( 'progressTimer', voiceProgressSet( voiceID ) );

        } else {
          voicePlayObj[ 0 ].pause();
          $( this ).removeClass( 'playing' );
          clearInterval( voicePlayObj.attr( 'progresstimer' ) );
        }

      } else {
        var timer = voiceProgressSet( voiceID );
        var audio = $( '<audio autoplay="autoplay" style="display: none"></audio>' );
        audio
          .prop( 'id', idStr + voiceID + idLastStr )
          .prop( 'src', tencentVoiceUrl + voiceID )
          .attr( 'progressTimer', timer )
          .attr( 'voiceid', voiceID );
        $( this ).addClass( 'playing' ).after( audio );
      }
    }

    function voiceProgressSet( voiceID ) {

      return setInterval( function() {

        var voiceObj = $( document.getElementById( idStr + voiceID + idLastStr ) );

        var currenttime = voiceObj[ 0 ].currentTime,
          duration = voiceObj[ 0 ].duration;
        $( document.getElementById( 'voice_progress_' + voiceID ) ).css( 'width', currenttime / duration * 100 + '%' );

        if ( voiceObj[ 0 ].ended ) {

          clearInterval( voiceObj.attr( 'progresstimer' ) );
          $( document.getElementById( 'voice_main_' + voiceObj.attr( 'voiceid' ) + idLastStr ) ).removeClass( 'playing' )
        }

      }, .5e3 );

    }

    $( 'mpvoice', '.main_content' ).each( loopVoice );

    $( '.main_content' ).on( 'click', '.audio_area', playaudio );
  }() );

  //音乐播放
  ( function() {
    var tencentMusicUrl = 'http://ws.stream.qqmusic.qq.com/';
    var lastStr = '.m4a?fromtag=46',
      idStr = 'bw_qqmusic_';
    var idLastStr = '_0';

    function getMusicHtml( music ) {

      var musicName = music.attr( 'music_name' );
      var singerName = music.attr( 'singer' );
      var commentID = music.attr( 'commentid' );
      var musicID = music.attr( 'musicid' );
      var audiourl = music.attr( 'audiourl' );
      var albumurl = music.attr( 'albumurl' );

      var html = '';
      html += '<span id="qqmusic_main_' + musicID + idLastStr + '" class="db qqmusic_area ">';
      html += '<span class="tc tips_global unsupport_tips" style="display:none;">当前浏览器不支持播放音乐或语音，请在微信或其他浏览器中播放</span>';
      html += '<span class="db qqmusic_wrp">';
      html += '<span class="db qqmusic_bd">';
      html += '<span id="qqmusic_play_' + musicID + '_0" class="play_area">';
      html += '<i class="icon_qqmusic_switch"></i>';
      html += '<img src="http://res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/qqmusic/icon_qqmusic_default.2x26f1f1.png" alt="" class="pic_qqmusic_default">'
      html += '<img src="https://imgcache.qq.com/music/photo/mid_album_68' + albumurl + '" data-autourl=' + audiourl + ' data-musicid="' + musicID + '" class="qqmusic_thumb" alt="">';
      html += '</span>';
      html += '<a id="qqmusic_home_' + musicID + '_0" href="http://y.qq.com/#type=song&id=' + musicID + '" class="access_area">';
      html += '<span class="qqmusic_songname">' + musicName + '</span>';
      html += '<span class="qqmusic_singername">' + singerName + '</span>';
      html += '<span class="qqmusic_source">';
      html += '<img src="http://res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/qqmusic/icon_qqmusic_source263724.png" alt="">';
      html += '</span>';
      html += '</a>';
      html += '</span>';
      html += '</span>';
      html += '</span>';
      return html;
    }

    function loopMusic( index, item ) {
      var currentMusic = $( item );
      currentMusic.after( getMusicHtml( currentMusic ) );
    }

    function playMusic() {

      var autourl = $( '[data-autourl]', this ).attr( 'data-autourl' );
      var voiceID = $( '[data-autourl]', this ).attr( 'data-musicid' );

      var voicePlayObj = $( document.getElementById( idStr + voiceID ) );
      if ( voicePlayObj.length ) {
        if ( voicePlayObj[ 0 ].paused ) {
          voicePlayObj[ 0 ].play();
          $( this ).parent().parent().parent().addClass( 'qqmusic_playing' )
          voicePlayObj.attr( 'progressTimer', voiceProgressSet( voiceID ) );

        } else {
          voicePlayObj[ 0 ].pause();
          voicePlayObj[ 0 ].currentTime = 0;
          $( this ).parent().parent().parent().removeClass( 'qqmusic_playing' );
          clearInterval( voicePlayObj.attr( 'progresstimer' ) );
        }

      } else {
        var timer = voiceProgressSet( voiceID );
        var audio = $( '<audio autoplay="autoplay" style="display: none"></audio>' );
        audio
          .prop( 'id', idStr + voiceID )
          .prop( 'src', autourl )
          .attr( 'progressTimer', timer )
          .attr( 'voiceid', voiceID );
        $( this ).parent().parent().parent().addClass( 'qqmusic_playing' ).after( audio );
      }


    }

    function voiceProgressSet( voiceID ) {

      return setInterval( function() {

        var voiceObj = $( document.getElementById( idStr + voiceID ) );

        if ( voiceObj[ 0 ].ended ) {

          clearInterval( voiceObj.attr( 'progresstimer' ) );
          $( document.getElementById( 'qqmusic_main_' + voiceObj.attr( 'voiceid' ) + idLastStr ) ).removeClass( 'qqmusic_playing' )
        }

      }, .5e3 );

    }
    $( 'qqmusic', '.main_content' ).each( loopMusic );

    $( '.main_content' ).on( 'click', '.play_area ', playMusic );
  }() );

  // 文章cd
  var article_cd = $( '#article_cd' ).val();
  if ( !article_cd ) {
    ShowTitleMessage.showWarning( '文章不存在', showTime );
    window.location.href = '/resource/article';
  };


  // 原创转载
  if ( article_cd ) {
    $.ajax( {
      url: BIGWE_API.ARTICEL_PREVIEW.GET_ARTICLE_ISREPRINT,
      type: 'post',
      data: {
        cd: article_cd
      },
      success: function( data ) {
        data = $.parseJSON( data );
        if ( data.data.reprint_ext ) {
          var reprint = $( '.reprint_info' ).show();
          $( '.o_publisher', reprint ).text( data.data.reprint_ext.o_publisher || '' );
          $( '.o_title', reprint ).text( data.data.reprint_ext.o_title || '' ).prop( 'href', 'article?p=' + data.data.reprint_ext.opid );
        }
      }
    } );
  }

  // ============================= move from html
  $.ajax( {
    type: 'post',
    dataType: 'jsonp',
    url: h2Api.COLLECT,
    data: 'ak=' + c.applicationKey + '&&ds=bigwe.com&&uid={$user_login}&&aid={$article["cd"]}&&title={$article["title"]}&&dt=view'
  } )

  // 文章标题，去除非中英文数字的符号字符
  var article_title = $( '.con_head h2' ).text().replace( /[^\u4e00-\u9fa5a-zA-Z0-9]/ig, '' );
  /**
   * 获取推荐列表
   */
  $.get(
    apis.ARTICEL_PREVIEW.GET_REC_LS, {
      key: article_title
    },
    function( data ) {
      var arts = data.articles;
      var _html = '';
      for ( var i in arts ) {
        var item = arts[ i ];
        _html += '<div class="guess ' + ( item.cover_img_url ? '' : 'nocover' ) + '">';
        _html += '    <div class="text">';
        _html += '        <p><a data-cnzz-trackevent="' + behavior.guessArt + behavior.clickstr + c.userLoginBehavior + '" href="/article?p=' + item.cd + '"  target="_blank">' + item.title + '</a></p>';
        _html += '        <span>' + ( item.publisher || '' ) + '</span>';
        _html += '        <span>' + ( new Date( item.publish_time_millis * 1 ) ).format( 'yyyy-MM-dd hh:mm' ) + '</span>';
        _html += '    </div>';
        if ( item.cover_img_url ) {
          var img_src = ( bu.parseURL( item.cover_img_url ).hostname == 'www.cpanet.cn' ) ? ( item.cover_img_url ) : ( data.img_cdn + item.cover_img_url );
          _html += '    <a data-cnzz-trackevent="' + behavior.guessArt + behavior.clickstr + c.userLoginBehavior + '" class="img_link" href="/article?p=' + item.cd + '" target="_black"><img src="' + img_src + '" class="img"></a>';
        }
        _html += '</div>';

      }
      $( '.guess_list' ).append( _html );
    }
  );

  // 文章标签
  var tags = $( '#tags' ).attr( 'data' ),
    json = "";

  if ( tags ) {
    tag = tags.replace( /\[|\]/g, '' ).split( ',' )
    for ( var j = 0; j < tag.length; j++ ) {
      json += '<a href="/tag_preview?tag=' + $.trim( tag[ j ] ) + '" class="tagc1">' + $.trim( tag[ j ] ) + '</a>';
    }
    $( '#tagscloud' ).html( json );
  }

  // 设置视频宽高比
  $( '.rich_media_content' ).mediaFormat();

  /*分享*/
  if ( bu.contains( window.location.href, 'free_article' ) ) {
    var _url = window.location.href;
  } else {
    var _url = window.location.href.replace( /article/, "free_article" );
  }

  function get_pic() {
    var a = document.getElementsByTagName( 'img' ),
      pic = '',
      con = '',
      picArr = new Array();
    for ( i = 0; i < a.length; i++ ) {
      var b = parseInt( a.item( i ).offsetWidth ),
        imgH = parseInt( a.item( i ).offsetHeight ),
        minW = 300,
        minH = 150,
        width = ( 300 / imgH ) * 150,
        height = ( 150 / b ) * 300;
      if ( b >= minW && imgH >= minH ) {
        if ( ( width - height ) <= 150 ) {
          pic += con + a.item( i ).src;
          con = ','
        }
      }
    }
    picArr = pic.split( ',' );
    var c = parseInt( Math.random() * picArr.length );
    return picArr[ c ]
  }
  var a, b, s, t = 0;
  s = {
    title: $( '.content_hd > h2' ).text(),
    url: _url
  }, t = {
    jiathis: function( a, b, k ) {
      window.open( "http://www.jiathis.com/send/?webid=" + a + "&url=" + encodeURIComponent( b.url ) + "&title=" + encodeURIComponent( b.title ) + "&uid=2118247&pic=" + encodeURIComponent( b.img ) + "&summary=" + b.ma + "&appkey=" + k );
    }
  }, $( "#share" ).click( function( a ) {
    a.stopPropagation();
    s.img = get_pic();
    s.ma = $( "meta[name=description]" ).attr( 'content' );
    $.ajax( {
      type: 'post',
      url: apis.ARTICEL_PREVIEW.ADD_LOG_SHARE,
      data: {
        p: article_cd
      },
      success: function( data ) {
        var data = eval( '(' + data + ')' );
        if ( data.ret == 80234 ) {
          ShowTitleMessage.showWarning( '文章禁止转载...', 1500 );
          return;
        }
        if ( data.ret == 0 ) {
          share( a.target.className );
        }
      }
    } )
    a.preventDefault()
  } )

  function share( c ) {
    switch ( c ) {
      case "qzone":
        t.jiathis( "qzone", s, '101286682' );
        break;
      case "sina":
        t.jiathis( "tsina", s, '2121870539' );
        break;
      case "weixin":
        createRcode( "weixin", s, 'wxdba5a2585af43f78' );
        break;
    }
  }

  function createRcode( j, c ) {
    var f, wt, ft, innerhtml, mt, width, height, bh, mt, isIe6 = /msie|MSIE 6/.test( navigator.userAgent );
    if ( g = document.getElementById( 'weixin_share' ) ) {
      g = document.getElementById( 'weixin_share' )
    } else {
      var g = document.createElement( "div" );
      if ( isIe6 ) {
        g.style.position = "absolute";
        g.style.zIndex = "1000";
        g.style.left = '650px';
        var h = document.body.scrollTop || document.documentElement.scrollTop;
        g.style.top = parseInt( h ) + 300 + 'px'
      } else {
        g.style.position = "fixed";
        g.style.zIndex = "1000"
      }
      g.id = 'weixin_share'
    }
    f = "http://www.jiathis.com/send/?webid=" + j + "&url=" + encodeURIComponent( c.url ) + "&title=" + encodeURIComponent( c.title ) + "&uid=2118247";
    wt = '分享到微信朋友圈';
    ft = '打开微信，点击底部的“发现”，使用 “扫一扫” 即可将网页分享到我的朋友圈。 <a href="' + f + '" target="_blank">如何使用？</a>';
    innerhtml = innerhtmlw = '二维码加载中....';
    width = 'width:360px;';
    height = 'height:360px;';
    bh = 'height:251px;';
    mt = 'margin: -200px 0 0 -200px;'
    g.innerHTML = '<div id="weixin_modal" style="background-clip: padding-box;background-color: #FFFFFF;border: 1px solid rgba(0, 0, 0, 0.3);  border-radius: 6px 6px 6px 6px;  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3); left: 50%; ' + mt + 'overflow: hidden; position: fixed; top: 50%; ' + width + height + ' overflow:hidden;" class="weixin_modal">' + '<div class="modal_header" id="modal_header" style="border-bottom: 1px solid #EEEEEE; padding: 9px 15px;">' + '<a style="text-decoration:none;margin-top: 2px;color: #000000;float: right;font-size: 20px;  font-weight: bold;cursor:pointer;line-height: 20px;opacity: 0.2;text-shadow: 0 1px 0 #FFFFFF;" class="weixin_close" target="_self">×</a>' + '<h3 id="weixin_h3"style=" line-height: 30px; margin: 0; font-weight:normal; font-family:"微软雅黑";">' + wt + '</h3>' + '</div><div class="modal_body"id="modal_body"style="text-align:center;' + bh + '"><p id="webchat">' + innerhtml + '</p></div><div class="modal_footer" id="modal_footer"style="border-radius: 0 0 6px 6px; border-top: 1px solid #DDDDDD; box-shadow: 0 1px 0 #FFFFFF inset; height:100%;padding:0 10px;padding-top:11px;text-align: right; font-size:12px;"><div id="weixin_tip"style="text-align:left;margin:0; padding:0;font-size:12px;">' + ft + '</div>  </div></div>';
    document.body.appendChild( g );
    setTimeout( function() {
      var a = document.createElement( 'img' );
      var b = document.getElementById( 'webchat' );
      a.src = 'http://s.jiathis.com/qrcode.php?url=' + c.url;
      a.width = '220';
      a.height = '220';
      a.style.marginTop = '15px';
      b.innerHTML = '';
      a.alt = '二维码加载失败...';
      b.appendChild( a )
    }, 1000 );
    weixin_qr_cancel();
  }

  function weixin_qr_cancel() {
    $( '.weixin_close' ).click( function() {
      $( '#weixin_share' ).remove();
    } )
    $( document ).bind( 'click.weixin_modal', function() {
      $( '#weixin_share' ).remove();
      $( document ).unbind( "click.weixin_modal" );
    } );
  }

  /*点赞*/

  $( '.cz_btn_like' ).click( function() {
    $.ajax( {
      type: 'post',
      url: apis.ARTICEL_PREVIEW.LIKE_ART,
      data: {
        cd: article_cd
      },
      success: function( data ) {
        $( ".like_num" ).text( data.data.like_num );
        var likeText = '';
        if ( data.data.is_liked == 1 ) {
          $( '.cz_btn_like' ).addClass( 'cz_btn_opt' ).removeClass( 'cz_btn' );
          likeText = behavior.action.like;
        } else {
          $( '.cz_btn_like' ).addClass( 'cz_btn' ).removeClass( 'cz_btn_opt' );
          likeText = behavior.action.unlike;
        }

        behavior.addRecord( {
          category: behavior.artcle,
          action: likeText,
          label: c.userLoginBehavior
        } );
      }
    } )
  } )

  /*
   * 分组列表
   */
  var group_slt = true;

  function fz_slt() {
    group_slt = false;
    if ( !$( '#user_login' ).val() ) {
      return;
    }
    $.ajax( {
      type: 'get',
      dataType: 'json',
      url: apis.COMMON.GET_MEDIA,
      data: {
        rt: 'collectArt'
      },
      success: function( data ) {
        if ( data.ret == 0 ) {
          group = data.data;
          var li = '';
          if ( group.length * 1 != 0 ) {
            li += '<option value="">未分组</option>'
            for ( var i in group ) {
              li += '<option value="' + group[ i ].id + '">' + group[ i ].group_name + '</option>';
            }
            $( 'select.group_select' ).empty().append( li );
          }
          $( '.group_select' ).data( 'list', false ).attr( 'data-list', 'false' );
          $( '.selectpicker' ).selectpicker( 'refresh' );
        }
      }
    } );
  }

  fz_slt();

  /*收藏*/
  $( '.cz_btn_collect' ).click( function( e ) {
    e.stopPropagation();
    $( ".art_collect" ).slideDown();
    if ( $( this ).hasClass( 'cz_btn_opt' ) ) {
      $( ".add_collect" ).addClass( 'hide' );
      $( ".cancel_collect" ).removeClass( 'hide' );
    } else {
      $( ".add_collect" ).removeClass( 'hide' );
      $( ".cancel_collect" ).addClass( 'hide' );
    }
    if ( group_slt ) {
      fz_slt();
    }
  } );

  $( '.establish_group' ).click( function() {
    $( this ).addClass( 'hide' ).siblings().removeClass( 'hide' ).focus();
    if ( $( 'select.group_select' ).val() != '' ) {
      $( '.selectpicker' ).selectpicker( 'val', '' );
      $( '.selectpicker' ).selectpicker( 'refresh' );
    }
  } )

  $( 'select.group_select' ).change( function() {
    if ( !$( '.establish' ).is( 'hidden' ) ) {
      $( '.establish' ).addClass( 'hide' ).val( '' ).siblings().removeClass( 'hide' );
    }
  } )

  $( '.add_collect' ).on( 'click', '.sure', function() {
    var collect_group = '';
    collect_group = $( 'select.group_select' ).val() || $( '.establish' ).val();

    $( ".art_collect" ).slideUp();
    var cd = $( this ).data( "cd" );

    if ( $( 'select.group_select' ).val() != '' || collect_group == '' ) {
      $.post( BIGWE_API.COLLECT_ART.GET_COLLECT_ART, {
        cd: cd,
        cgid: collect_group,
        rt: 'collectArt'
      }, function( data ) {
        data = typeof data === 'string' ? JSON.parse( data ) : data;
        if ( data.ret != 44444 && data.ret === 0 ) {
          $.get( apis.MYCOLLECTION.CG, {
            cd: data.data.cd,
            cgid: collect_group,
            rt: 'collectArt'
          }, function( data ) {
            ShowTitleMessage.show( '收藏成功!', showTime );
            behavior.addRecord( {
              category: behavior.artcle,
              action: behavior.action.collect,
              label: c.userLoginBehavior
            } );
          } );
          $( '.cz_btn_collect' ).find( "a" ).text( "取消收藏" );
          $( '.cz_btn_collect' ).addClass( "cz_btn_opt" ).removeClass( "cz_btn" );
        }
      } );
    } else {
      var val = $( ".establish" ).val();
      $.get( apis.MYCOLLECTION.ADD_GROUP, {
        rt: 'collectArt',
        cgn: val
      }, function( data ) {
        data = typeof data === 'string' ? JSON.parse( data ) : data;
        var art = data.data;
        _id = art.id;
        $.get( apis.COLLECT_ART.GET_COLLECT_ART, {
          cd: cd,
          rt: 'collectArt'
        }, function( dataRet ) {
          var dataRet = typeof dataRet === 'string' ? JSON.parse( dataRet ) : data;
          $.get( apis.MYCOLLECTION.CG, {
            cd: dataRet.data.cd,
            cgid: _id,
            rt: 'collectArt'
          }, function( data ) {
            ShowTitleMessage.show( '收藏成功!', showTime );
            fz_slt();
          } );

          $( '.cz_btn_collect' ).find( "a" ).text( "取消收藏" );
          $( '.cz_btn_collect' ).addClass( "cz_btn_opt" ).removeClass( "cz_btn" );
        } );
      } )
    }
  } )


  $( ".cancel" ).click( function() {
    $( ".art_collect" ).slideUp();
  } )
  $( ".confirm" ).click( function() {
    $( ".art_collect" ).slideUp();
    $( '.cz_btn_collect' ).find( "a" ).text( "收藏" );
    $( '.cz_btn_collect' ).addClass( "cz_btn" ).removeClass( "cz_btn_opt" );
    $.get( apis.MYCOLLECTION.FAVORITES_DEL, {
      id: article_cd,
      rt: 'collectArt'
    }, function( data ) {
      ShowTitleMessage.showWarning( '取消收藏成功!', showTime );
    } );
  } );

  $( document ).bind( 'click', function( e ) {
    var e = e || window.event; //浏览器兼容性 
    var elem = e.target || e.srcElement;
    while ( elem ) { //循环判断至跟节点，防止点击的是div子元素 
      if ( elem.id && elem.id == 'art_collect' ) {
        return;
      }
      elem = elem.parentNode;
    }

    $( ".art_collect" ).slideUp(); //点击的不是div或其子元素 
  } );

  if ( $( ".con_left" ).height() < 400 ) {
    $( ".art_collect" ).css( {
      top: "13px"
    } );
  } else {
    $( ".art_collect" ).css( {
      bottom: "164px"
    } );
  }
} );
